package ly.count.ohos.sdk;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import ohos.testkit.runner.OhosJUnitClassRunner;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(OhosJUnitClassRunner.class)
public class CountlyConfigTests {

    private Context getContext() {
        Context context = AbilityDelegatorRegistry.getAbilityDelegator().getCurrentTopAbility().getContext();
        return context;
    }

    @Before
    public void setUp() {
        Countly.sharedInstance().setLoggingEnabled(true);
    }

    @Test
    public void constructor() {
        CountlyConfig config = new CountlyConfig(getContext(), "Som345345", "fsdf7349374");

        assertDefaultValues(config, false);
    }

    @Test
    public void defaultValues() {
        CountlyConfig config = new CountlyConfig();

        assertDefaultValues(config, true);
    }

    @Test(expected = IllegalArgumentException.class)
    public void autoTrackingExceptionNull() {
        CountlyConfig config = new CountlyConfig();
        config.setAutoTrackingExceptions(new Class[] { null });
    }

    void assertDefaultValues(CountlyConfig config, boolean includeConstructorValues) {
        if (includeConstructorValues) {
            Assert.assertNull(config.context);
            Assert.assertNull(config.serverURL);
            Assert.assertNull(config.appKey);
        }

        Assert.assertNull(config.countlyStore);
        Assert.assertTrue(config.checkForNativeCrashDumps);
        Assert.assertNull(config.deviceID);
        Assert.assertNull(config.idMode);
        Assert.assertEquals(5, config.starRatingSessionLimit);
        Assert.assertNull(config.starRatingCallback);
        Assert.assertNull(config.starRatingTextDismiss);
        Assert.assertNull(config.starRatingTextMessage);
        Assert.assertNull(config.starRatingTextTitle);
        Assert.assertFalse(config.loggingEnabled);
        Assert.assertFalse(config.enableUnhandledCrashReporting);
        Assert.assertFalse(config.enableViewTracking);
        Assert.assertFalse(config.autoTrackingUseShortName);
        Assert.assertNull(config.customNetworkRequestHeaders);
        Assert.assertFalse(config.pushIntentAddMetadata);
        Assert.assertFalse(config.enableRemoteConfigAutomaticDownload);
        Assert.assertNull(config.remoteConfigCallback);
        Assert.assertFalse(config.shouldRequireConsent);
        Assert.assertNull(config.enabledFeatureNames);
        Assert.assertFalse(config.httpPostForced);
        Assert.assertFalse(config.temporaryDeviceIdEnabled);
        Assert.assertNull(config.crashFilterCallback);
        Assert.assertNull(config.tamperingProtectionSalt);
        Assert.assertNull(config.automaticViewSegmentation);
        Assert.assertNull(config.eventQueueSizeThreshold);
        Assert.assertFalse(config.trackOrientationChange);
        Assert.assertFalse(config.manualSessionControlEnabled);
        Assert.assertFalse(config.recordAllThreadsWithCrash);
        Assert.assertFalse(config.disableUpdateSessionRequests);
        Assert.assertFalse(config.shouldIgnoreAppCrawlers);
        Assert.assertNull(config.appCrawlerNames);
        Assert.assertNull(config.publicKeyPinningCertificates);
        Assert.assertNull(config.certificatePinningCertificates);
        Assert.assertNull(config.enableAttribution);
        Assert.assertNull(config.customCrashSegment);
        Assert.assertNull(config.sessionUpdateTimerDelay);
        Assert.assertFalse(config.starRatingDialogIsCancellable);
        Assert.assertFalse(config.starRatingShownAutomatically);
        Assert.assertFalse(config.starRatingDisableAskingForEachAppVersion);
        Assert.assertNull(config.application);
        Assert.assertFalse(config.recordAppStartTime);
        Assert.assertFalse(config.disableLocation);
        Assert.assertNull(config.locationCountyCode);
        Assert.assertNull(config.locationCity);
        Assert.assertNull(config.locationLocation);
        Assert.assertNull(config.locationIpAddress);
        Assert.assertNull(config.metricOverride);
    }
}
